package logic;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class Score {
	
	private LinkedList<ScoreElement> elements;
	
	public Score() {
		elements = new LinkedList<ScoreElement>();
	}
	
	public void addElement(ScoreElement element){
		elements.add(element);
		Collections.sort(elements);
	}
	
	public void removeElement(ScoreElement element){
		elements.remove(element);
		Collections.sort(elements);
	}
	
	public ScoreElement first(){
		return elements.getFirst();
	}
	
	public ScoreElement last(){
		return elements.getLast();
	}
	
	public double mean(){
		
		double sum = 0;
		
		for (int i = 0; i < elements.size(); i++) {
			sum += elements.get(i).value;
		}
		
		return sum/elements.size();
		
	}
	
	@SuppressWarnings("unchecked")
	public List<ScoreElement> list(){
		return (List<ScoreElement>) elements.clone();
	}
	
	@Override
	public String toString() {
		String str = "";
		
		for (int i = 0; i < elements.size(); i++) {
			str += (i + 1) + " - " + elements.get(i) + "\n"; 
		}
		
		return str;
	}
}
